package com.xinhe.web.controller;

import com.querydsl.core.QueryResults;
import com.xinhe.web.annotation.WebUsed;
import com.xinhe.web.common.Result;
import com.xinhe.web.entity.Role;
import com.xinhe.web.service.RoleService;
import com.xinhe.web.vo.RoleView;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(value = "系统角色", tags = {"系统角色"})
@RestController
@RequestMapping(value = {"/role"}, produces = {"application/json;charset=UTF-8"})
public class RoleController {
    @Autowired
    private RoleService roleService;

    @WebUsed
    @ApiOperation(httpMethod = "GET", value = "分页查询系统角色")
    @RequestMapping({"/pageRole"})
    public QueryResults<RoleView> pageRole(String keyword, Integer terminal, Long parentRoleId, Long platformUserId,
                                           int pageNum, int pageSize) {
        return this.roleService.pageRole( keyword,  terminal,  parentRoleId,  platformUserId,
         pageNum,  pageSize);
    }

    @WebUsed
    @ApiOperation(httpMethod = "POST", value = "保存系统角色")
    @RequestMapping({"/saveRole"})
    public Result saveRole(String name,Integer terminal,Long parentRoleId,Long platformUserId,String remark){
        return this.roleService.saveModel(name, terminal, parentRoleId, platformUserId, remark);
    }

    @WebUsed
    @ApiOperation(httpMethod = "GET", value = "删除系统角色")
    @ApiImplicitParam(name = "roleId", value = "标识", dataTypeClass = Long.class, required = true)
    @RequestMapping({"/deleteRole"})
    public Result deleteRole(Long roleId) {
        return this.roleService.delete(roleId);
    }

    @WebUsed
    @ApiOperation(httpMethod = "GET", value = "系统角色详情")
    @ApiImplicitParam(name = "roleId", value = "标识", dataTypeClass = Long.class, required = true)
    @RequestMapping({"/detailRole"})
    public Result<Role> detailRole(Long roleId) {
        return this.roleService.findById(roleId);
    }

}